{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['figure.figsize']=(15,8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 从文件中载入数据\n",
    "df_xtrain = pd.read_table('14cancer.xtrain',sep='\\s+',header=None, encoding='utf-8')\n",
    "df_ytrain = pd.read_table('14cancer.ytrain',sep='\\s+',header=None, encoding='utf-8')\n",
    "df_xtest = pd.read_table('14cancer.xtest',sep='\\s+',header=None, encoding='utf-8')\n",
    "df_ytest = pd.read_table('14cancer.ytest',sep='\\s+',header=None, encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(16063, 144) (1, 144) (16063, 54) (1, 54)\n"
     ]
    }
   ],
   "source": [
    "# 查看数据的形状\n",
    "# shape=(n_genes,n_samples),shape=(1,n_class)\n",
    "print(df_xtrain.shape,df_ytrain.shape,df_xtest.shape,df_ytest.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>134</th>\n",
       "      <th>135</th>\n",
       "      <th>136</th>\n",
       "      <th>137</th>\n",
       "      <th>138</th>\n",
       "      <th>139</th>\n",
       "      <th>140</th>\n",
       "      <th>141</th>\n",
       "      <th>142</th>\n",
       "      <th>143</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-73</td>\n",
       "      <td>-16</td>\n",
       "      <td>4</td>\n",
       "      <td>-31</td>\n",
       "      <td>-33</td>\n",
       "      <td>-37</td>\n",
       "      <td>-18</td>\n",
       "      <td>-26</td>\n",
       "      <td>-40</td>\n",
       "      <td>22</td>\n",
       "      <td>...</td>\n",
       "      <td>274</td>\n",
       "      <td>-96</td>\n",
       "      <td>-96</td>\n",
       "      <td>-124</td>\n",
       "      <td>-201</td>\n",
       "      <td>-196</td>\n",
       "      <td>34</td>\n",
       "      <td>-56</td>\n",
       "      <td>-245</td>\n",
       "      <td>-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-69</td>\n",
       "      <td>-63</td>\n",
       "      <td>-45</td>\n",
       "      <td>-110</td>\n",
       "      <td>-39</td>\n",
       "      <td>-90</td>\n",
       "      <td>28</td>\n",
       "      <td>-23</td>\n",
       "      <td>-264</td>\n",
       "      <td>-14</td>\n",
       "      <td>...</td>\n",
       "      <td>-915</td>\n",
       "      <td>-221</td>\n",
       "      <td>-458</td>\n",
       "      <td>-664</td>\n",
       "      <td>-259</td>\n",
       "      <td>-369</td>\n",
       "      <td>-81</td>\n",
       "      <td>-818</td>\n",
       "      <td>-235</td>\n",
       "      <td>-1595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-48</td>\n",
       "      <td>-97</td>\n",
       "      <td>-112</td>\n",
       "      <td>-20</td>\n",
       "      <td>-45</td>\n",
       "      <td>-75</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>-335</td>\n",
       "      <td>-21</td>\n",
       "      <td>...</td>\n",
       "      <td>-303</td>\n",
       "      <td>-119</td>\n",
       "      <td>-134</td>\n",
       "      <td>-361</td>\n",
       "      <td>22</td>\n",
       "      <td>-263</td>\n",
       "      <td>-146</td>\n",
       "      <td>-1338</td>\n",
       "      <td>-127</td>\n",
       "      <td>-2085</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13</td>\n",
       "      <td>-42</td>\n",
       "      <td>-25</td>\n",
       "      <td>-50</td>\n",
       "      <td>14</td>\n",
       "      <td>-46</td>\n",
       "      <td>30</td>\n",
       "      <td>34</td>\n",
       "      <td>18</td>\n",
       "      <td>26</td>\n",
       "      <td>...</td>\n",
       "      <td>29</td>\n",
       "      <td>243</td>\n",
       "      <td>109</td>\n",
       "      <td>21</td>\n",
       "      <td>140</td>\n",
       "      <td>162</td>\n",
       "      <td>-151</td>\n",
       "      <td>-57</td>\n",
       "      <td>197</td>\n",
       "      <td>-334</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-86</td>\n",
       "      <td>-91</td>\n",
       "      <td>-85</td>\n",
       "      <td>-115</td>\n",
       "      <td>-56</td>\n",
       "      <td>-45</td>\n",
       "      <td>-56</td>\n",
       "      <td>-54</td>\n",
       "      <td>-163</td>\n",
       "      <td>-42</td>\n",
       "      <td>...</td>\n",
       "      <td>-171</td>\n",
       "      <td>-224</td>\n",
       "      <td>-630</td>\n",
       "      <td>-519</td>\n",
       "      <td>-277</td>\n",
       "      <td>-277</td>\n",
       "      <td>-174</td>\n",
       "      <td>-989</td>\n",
       "      <td>-562</td>\n",
       "      <td>-455</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 144 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   0    1    2    3    4    5    6    7    8    9    ...   134  135  136  137  \\\n",
       "0  -73  -16    4  -31  -33  -37  -18  -26  -40   22  ...   274  -96  -96 -124   \n",
       "1  -69  -63  -45 -110  -39  -90   28  -23 -264  -14  ...  -915 -221 -458 -664   \n",
       "2  -48  -97 -112  -20  -45  -75   10    2 -335  -21  ...  -303 -119 -134 -361   \n",
       "3   13  -42  -25  -50   14  -46   30   34   18   26  ...    29  243  109   21   \n",
       "4  -86  -91  -85 -115  -56  -45  -56  -54 -163  -42  ...  -171 -224 -630 -519   \n",
       "\n",
       "   138  139  140   141  142   143  \n",
       "0 -201 -196   34   -56 -245   -26  \n",
       "1 -259 -369  -81  -818 -235 -1595  \n",
       "2   22 -263 -146 -1338 -127 -2085  \n",
       "3  140  162 -151   -57  197  -334  \n",
       "4 -277 -277 -174  -989 -562  -455  \n",
       "\n",
       "[5 rows x 144 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对数据进行预览\n",
    "df_xtrain.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 对数据进行初步清洗，消除nan值\n",
    "def drop_df_nan(df_x,df_y): \n",
    "    # x: dataframe shape=(m,n)   n: the number of samples\n",
    "    # y: dataframe shape=(1,n)\n",
    "    # 删除样本中那些包含nan值的样本（列）\n",
    "    nan_x_index = np.where(np.isnan(df_x))   # 返回np.nan值所在的行和列 （rows_index，columns_index）\n",
    "    nan_y_index = np.where(np.isnan(df_y)) \n",
    "    nan_rows = np.union1d(nan_x_index[0],nan_y_index[0])   # 求取两个并集\n",
    "    nan_cols = np.union1d(nan_x_index[1],nan_y_index[1])\n",
    "    #print(list(df_x.columns[nan_cols]),type(list(df_x.columns[nan_cols])))\n",
    "    if len(nan_cols)!= 0:              # 如果返回的列索引值非空，即存在某些列存在np.nan值，我们进行删除,注意drop不改变元对象\n",
    "        df_x=df_x.drop(columns=nan_cols)\n",
    "        df_y=df_y.drop(columns=nan_cols)\n",
    "    return df_x,df_y\n",
    "df_xtrain,df_ytrain = drop_df_nan(df_xtrain, df_ytrain)\n",
    "df_xtest, df_ytest = drop_df_nan(df_xtest, df_ytest)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 按照机器学习中的常规习惯，我们将数据进行转置，使shape=(n_samples,d)\n",
    "df_xtrain = df_xtrain.T\n",
    "df_xtest = df_xtest.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>16053</th>\n",
       "      <th>16054</th>\n",
       "      <th>16055</th>\n",
       "      <th>16056</th>\n",
       "      <th>16057</th>\n",
       "      <th>16058</th>\n",
       "      <th>16059</th>\n",
       "      <th>16060</th>\n",
       "      <th>16061</th>\n",
       "      <th>16062</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-73.0</td>\n",
       "      <td>-69.0</td>\n",
       "      <td>-48.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>-86.0</td>\n",
       "      <td>-147.0</td>\n",
       "      <td>-65.0</td>\n",
       "      <td>-71.0</td>\n",
       "      <td>-32.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-134.0</td>\n",
       "      <td>352.0</td>\n",
       "      <td>-67.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>-5.0</td>\n",
       "      <td>-11.0</td>\n",
       "      <td>-21.0</td>\n",
       "      <td>-41.0</td>\n",
       "      <td>-967.0</td>\n",
       "      <td>-120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-16.0</td>\n",
       "      <td>-63.0</td>\n",
       "      <td>-97.0</td>\n",
       "      <td>-42.0</td>\n",
       "      <td>-91.0</td>\n",
       "      <td>-164.0</td>\n",
       "      <td>-53.0</td>\n",
       "      <td>-77.0</td>\n",
       "      <td>-17.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-51.0</td>\n",
       "      <td>244.0</td>\n",
       "      <td>-15.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>-32.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>-14.0</td>\n",
       "      <td>-28.0</td>\n",
       "      <td>-205.0</td>\n",
       "      <td>-31.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.0</td>\n",
       "      <td>-45.0</td>\n",
       "      <td>-112.0</td>\n",
       "      <td>-25.0</td>\n",
       "      <td>-85.0</td>\n",
       "      <td>-127.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>-110.0</td>\n",
       "      <td>81.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>...</td>\n",
       "      <td>14.0</td>\n",
       "      <td>163.0</td>\n",
       "      <td>-14.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>-8.0</td>\n",
       "      <td>-104.0</td>\n",
       "      <td>-36.0</td>\n",
       "      <td>-245.0</td>\n",
       "      <td>34.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-31.0</td>\n",
       "      <td>-110.0</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>-50.0</td>\n",
       "      <td>-115.0</td>\n",
       "      <td>-113.0</td>\n",
       "      <td>-17.0</td>\n",
       "      <td>-40.0</td>\n",
       "      <td>-17.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>...</td>\n",
       "      <td>26.0</td>\n",
       "      <td>625.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>59.0</td>\n",
       "      <td>-10.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>-2.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>-495.0</td>\n",
       "      <td>-37.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-33.0</td>\n",
       "      <td>-39.0</td>\n",
       "      <td>-45.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>-56.0</td>\n",
       "      <td>-106.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>-34.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-69.0</td>\n",
       "      <td>398.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>-2.0</td>\n",
       "      <td>44.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>-293.0</td>\n",
       "      <td>-34.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 16063 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   0      1      2      3      4      5      6      7      8      9      \\\n",
       "0  -73.0  -69.0  -48.0   13.0  -86.0 -147.0  -65.0  -71.0  -32.0  100.0   \n",
       "1  -16.0  -63.0  -97.0  -42.0  -91.0 -164.0  -53.0  -77.0  -17.0  122.0   \n",
       "2    4.0  -45.0 -112.0  -25.0  -85.0 -127.0   56.0 -110.0   81.0   41.0   \n",
       "3  -31.0 -110.0  -20.0  -50.0 -115.0 -113.0  -17.0  -40.0  -17.0   80.0   \n",
       "4  -33.0  -39.0  -45.0   14.0  -56.0 -106.0   73.0  -34.0   18.0   64.0   \n",
       "\n",
       "   ...    16053  16054  16055  16056  16057  16058  16059  16060  16061  16062  \n",
       "0  ...   -134.0  352.0  -67.0  121.0   -5.0  -11.0  -21.0  -41.0 -967.0 -120.0  \n",
       "1  ...    -51.0  244.0  -15.0  119.0  -32.0    4.0  -14.0  -28.0 -205.0  -31.0  \n",
       "2  ...     14.0  163.0  -14.0    7.0   15.0   -8.0 -104.0  -36.0 -245.0   34.0  \n",
       "3  ...     26.0  625.0   18.0   59.0  -10.0   32.0   -2.0   10.0 -495.0  -37.0  \n",
       "4  ...    -69.0  398.0   38.0  215.0   -2.0   44.0    3.0   68.0 -293.0  -34.0  \n",
       "\n",
       "[5 rows x 16063 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 观察调整后的数据\n",
    "df_xtrain.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>16053</th>\n",
       "      <th>16054</th>\n",
       "      <th>16055</th>\n",
       "      <th>16056</th>\n",
       "      <th>16057</th>\n",
       "      <th>16058</th>\n",
       "      <th>16059</th>\n",
       "      <th>16060</th>\n",
       "      <th>16061</th>\n",
       "      <th>16062</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-44.0</td>\n",
       "      <td>-254.0</td>\n",
       "      <td>-166.0</td>\n",
       "      <td>-55.0</td>\n",
       "      <td>-130.0</td>\n",
       "      <td>-133.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>-62.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-51.0</td>\n",
       "      <td>715.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>-270.0</td>\n",
       "      <td>-265.0</td>\n",
       "      <td>-290.0</td>\n",
       "      <td>-235.0</td>\n",
       "      <td>-826.0</td>\n",
       "      <td>-262.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-13.0</td>\n",
       "      <td>-124.0</td>\n",
       "      <td>-206.0</td>\n",
       "      <td>-29.0</td>\n",
       "      <td>-117.0</td>\n",
       "      <td>-114.0</td>\n",
       "      <td>111.0</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>-25.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-57.0</td>\n",
       "      <td>695.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>57.0</td>\n",
       "      <td>-50.0</td>\n",
       "      <td>-45.0</td>\n",
       "      <td>-61.0</td>\n",
       "      <td>-22.0</td>\n",
       "      <td>-263.0</td>\n",
       "      <td>-52.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-64.3</td>\n",
       "      <td>-184.9</td>\n",
       "      <td>-334.4</td>\n",
       "      <td>-102.2</td>\n",
       "      <td>-289.0</td>\n",
       "      <td>-145.2</td>\n",
       "      <td>-251.9</td>\n",
       "      <td>-150.9</td>\n",
       "      <td>-184.0</td>\n",
       "      <td>179.1</td>\n",
       "      <td>...</td>\n",
       "      <td>-173.4</td>\n",
       "      <td>1324.6</td>\n",
       "      <td>9.8</td>\n",
       "      <td>127.7</td>\n",
       "      <td>244.0</td>\n",
       "      <td>76.5</td>\n",
       "      <td>100.1</td>\n",
       "      <td>-69.6</td>\n",
       "      <td>-1444.3</td>\n",
       "      <td>-121.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-22.0</td>\n",
       "      <td>-169.0</td>\n",
       "      <td>-164.0</td>\n",
       "      <td>-32.0</td>\n",
       "      <td>-49.0</td>\n",
       "      <td>-141.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-22.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>...</td>\n",
       "      <td>21.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>-275.0</td>\n",
       "      <td>-230.0</td>\n",
       "      <td>-136.0</td>\n",
       "      <td>-228.0</td>\n",
       "      <td>-404.0</td>\n",
       "      <td>-259.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-28.0</td>\n",
       "      <td>-167.0</td>\n",
       "      <td>-158.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>-129.0</td>\n",
       "      <td>-232.0</td>\n",
       "      <td>148.0</td>\n",
       "      <td>-48.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-66.0</td>\n",
       "      <td>1627.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>-6.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>-22.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>-1088.0</td>\n",
       "      <td>-58.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 16063 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   0      1      2      3      4      5      6      7      8      9      \\\n",
       "0  -44.0 -254.0 -166.0  -55.0 -130.0 -133.0   80.0  -62.0    1.0   22.0   \n",
       "1  -13.0 -124.0 -206.0  -29.0 -117.0 -114.0  111.0  -20.0  -25.0   18.0   \n",
       "2  -64.3 -184.9 -334.4 -102.2 -289.0 -145.2 -251.9 -150.9 -184.0  179.1   \n",
       "3  -22.0 -169.0 -164.0  -32.0  -49.0 -141.0    0.0  -22.0   16.0   67.0   \n",
       "4  -28.0 -167.0 -158.0  100.0 -129.0 -232.0  148.0  -48.0   14.0  164.0   \n",
       "\n",
       "   ...    16053   16054  16055  16056  16057  16058  16059  16060   16061  \\\n",
       "0  ...    -51.0   715.0   25.0   47.0 -270.0 -265.0 -290.0 -235.0  -826.0   \n",
       "1  ...    -57.0   695.0   10.0   57.0  -50.0  -45.0  -61.0  -22.0  -263.0   \n",
       "2  ...   -173.4  1324.6    9.8  127.7  244.0   76.5  100.1  -69.6 -1444.3   \n",
       "3  ...     21.0   170.0   20.0   35.0 -275.0 -230.0 -136.0 -228.0  -404.0   \n",
       "4  ...    -66.0  1627.0   76.0  119.0   -6.0   68.0  -22.0   27.0 -1088.0   \n",
       "\n",
       "   16062  \n",
       "0 -262.0  \n",
       "1  -52.0  \n",
       "2 -121.6  \n",
       "3 -259.0  \n",
       "4  -58.0  \n",
       "\n",
       "[5 rows x 16063 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_xtest.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将每个样本的类别添加到dataframe的第1列\n",
    "df_xtrain.insert(0,'Type',df_ytrain.T)\n",
    "df_xtest.insert(0,'Type',df_ytest.T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Type</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>...</th>\n",
       "      <th>2298</th>\n",
       "      <th>2299</th>\n",
       "      <th>2300</th>\n",
       "      <th>2301</th>\n",
       "      <th>2302</th>\n",
       "      <th>2303</th>\n",
       "      <th>2304</th>\n",
       "      <th>2305</th>\n",
       "      <th>2306</th>\n",
       "      <th>2307</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0.773344</td>\n",
       "      <td>-2.438405</td>\n",
       "      <td>-0.482562</td>\n",
       "      <td>-2.721135</td>\n",
       "      <td>-1.217058</td>\n",
       "      <td>0.827809</td>\n",
       "      <td>1.342604</td>\n",
       "      <td>0.057042</td>\n",
       "      <td>0.133569</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.238511</td>\n",
       "      <td>-0.027474</td>\n",
       "      <td>-1.660205</td>\n",
       "      <td>0.588231</td>\n",
       "      <td>-0.463624</td>\n",
       "      <td>-3.952845</td>\n",
       "      <td>-5.496768</td>\n",
       "      <td>-1.414282</td>\n",
       "      <td>-0.647600</td>\n",
       "      <td>-1.763172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>-0.078178</td>\n",
       "      <td>-2.415754</td>\n",
       "      <td>0.412772</td>\n",
       "      <td>-2.825146</td>\n",
       "      <td>-0.626236</td>\n",
       "      <td>0.054488</td>\n",
       "      <td>1.429498</td>\n",
       "      <td>-0.120249</td>\n",
       "      <td>0.456792</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.657394</td>\n",
       "      <td>-0.246284</td>\n",
       "      <td>-0.836325</td>\n",
       "      <td>-0.571284</td>\n",
       "      <td>0.034788</td>\n",
       "      <td>-2.478130</td>\n",
       "      <td>-3.661264</td>\n",
       "      <td>-1.093923</td>\n",
       "      <td>-1.209320</td>\n",
       "      <td>-0.824395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>-0.084469</td>\n",
       "      <td>-1.649739</td>\n",
       "      <td>-0.241307</td>\n",
       "      <td>-2.875286</td>\n",
       "      <td>-0.889405</td>\n",
       "      <td>-0.027474</td>\n",
       "      <td>1.159300</td>\n",
       "      <td>0.015676</td>\n",
       "      <td>0.191942</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.696352</td>\n",
       "      <td>0.024985</td>\n",
       "      <td>-1.059872</td>\n",
       "      <td>-0.403767</td>\n",
       "      <td>-0.678653</td>\n",
       "      <td>-2.939352</td>\n",
       "      <td>-2.736450</td>\n",
       "      <td>-1.965399</td>\n",
       "      <td>-0.805868</td>\n",
       "      <td>-1.139434</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>0.965614</td>\n",
       "      <td>-2.380547</td>\n",
       "      <td>0.625297</td>\n",
       "      <td>-1.741256</td>\n",
       "      <td>-0.845366</td>\n",
       "      <td>0.949687</td>\n",
       "      <td>1.093801</td>\n",
       "      <td>0.819736</td>\n",
       "      <td>-0.284620</td>\n",
       "      <td>...</td>\n",
       "      <td>0.259746</td>\n",
       "      <td>0.357115</td>\n",
       "      <td>-1.893128</td>\n",
       "      <td>0.255107</td>\n",
       "      <td>0.163309</td>\n",
       "      <td>-1.021929</td>\n",
       "      <td>-2.077843</td>\n",
       "      <td>-1.127629</td>\n",
       "      <td>0.331531</td>\n",
       "      <td>-2.179483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>0.075664</td>\n",
       "      <td>-1.728785</td>\n",
       "      <td>0.852626</td>\n",
       "      <td>0.272695</td>\n",
       "      <td>-1.841370</td>\n",
       "      <td>0.327936</td>\n",
       "      <td>1.251219</td>\n",
       "      <td>0.771450</td>\n",
       "      <td>0.030917</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.200404</td>\n",
       "      <td>0.061753</td>\n",
       "      <td>-2.273998</td>\n",
       "      <td>-0.039365</td>\n",
       "      <td>0.368801</td>\n",
       "      <td>-2.566551</td>\n",
       "      <td>-1.675044</td>\n",
       "      <td>-1.082050</td>\n",
       "      <td>-0.965218</td>\n",
       "      <td>-1.836966</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 2309 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Type         0         1         2         3         4         5         6  \\\n",
       "0     2  0.773344 -2.438405 -0.482562 -2.721135 -1.217058  0.827809  1.342604   \n",
       "1     2 -0.078178 -2.415754  0.412772 -2.825146 -0.626236  0.054488  1.429498   \n",
       "2     2 -0.084469 -1.649739 -0.241307 -2.875286 -0.889405 -0.027474  1.159300   \n",
       "3     2  0.965614 -2.380547  0.625297 -1.741256 -0.845366  0.949687  1.093801   \n",
       "4     2  0.075664 -1.728785  0.852626  0.272695 -1.841370  0.327936  1.251219   \n",
       "\n",
       "          7         8    ...         2298      2299      2300      2301  \\\n",
       "0  0.057042  0.133569    ...    -0.238511 -0.027474 -1.660205  0.588231   \n",
       "1 -0.120249  0.456792    ...    -0.657394 -0.246284 -0.836325 -0.571284   \n",
       "2  0.015676  0.191942    ...    -0.696352  0.024985 -1.059872 -0.403767   \n",
       "3  0.819736 -0.284620    ...     0.259746  0.357115 -1.893128  0.255107   \n",
       "4  0.771450  0.030917    ...    -0.200404  0.061753 -2.273998 -0.039365   \n",
       "\n",
       "       2302      2303      2304      2305      2306      2307  \n",
       "0 -0.463624 -3.952845 -5.496768 -1.414282 -0.647600 -1.763172  \n",
       "1  0.034788 -2.478130 -3.661264 -1.093923 -1.209320 -0.824395  \n",
       "2 -0.678653 -2.939352 -2.736450 -1.965399 -0.805868 -1.139434  \n",
       "3  0.163309 -1.021929 -2.077843 -1.127629  0.331531 -2.179483  \n",
       "4  0.368801 -2.566551 -1.675044 -1.082050 -0.965218 -1.836966  \n",
       "\n",
       "[5 rows x 2309 columns]"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_xtrain.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Type</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>...</th>\n",
       "      <th>2298</th>\n",
       "      <th>2299</th>\n",
       "      <th>2300</th>\n",
       "      <th>2301</th>\n",
       "      <th>2302</th>\n",
       "      <th>2303</th>\n",
       "      <th>2304</th>\n",
       "      <th>2305</th>\n",
       "      <th>2306</th>\n",
       "      <th>2307</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>0.773344</td>\n",
       "      <td>-2.438405</td>\n",
       "      <td>-0.482562</td>\n",
       "      <td>-2.721135</td>\n",
       "      <td>-1.217058</td>\n",
       "      <td>0.827809</td>\n",
       "      <td>1.342604</td>\n",
       "      <td>0.057042</td>\n",
       "      <td>0.133569</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.238511</td>\n",
       "      <td>-0.027474</td>\n",
       "      <td>-1.660205</td>\n",
       "      <td>0.588231</td>\n",
       "      <td>-0.463624</td>\n",
       "      <td>-3.952845</td>\n",
       "      <td>-5.496768</td>\n",
       "      <td>-1.414282</td>\n",
       "      <td>-0.647600</td>\n",
       "      <td>-1.763172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>-0.078178</td>\n",
       "      <td>-2.415754</td>\n",
       "      <td>0.412772</td>\n",
       "      <td>-2.825146</td>\n",
       "      <td>-0.626236</td>\n",
       "      <td>0.054488</td>\n",
       "      <td>1.429498</td>\n",
       "      <td>-0.120249</td>\n",
       "      <td>0.456792</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.657394</td>\n",
       "      <td>-0.246284</td>\n",
       "      <td>-0.836325</td>\n",
       "      <td>-0.571284</td>\n",
       "      <td>0.034788</td>\n",
       "      <td>-2.478130</td>\n",
       "      <td>-3.661264</td>\n",
       "      <td>-1.093923</td>\n",
       "      <td>-1.209320</td>\n",
       "      <td>-0.824395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>-0.084469</td>\n",
       "      <td>-1.649739</td>\n",
       "      <td>-0.241307</td>\n",
       "      <td>-2.875286</td>\n",
       "      <td>-0.889405</td>\n",
       "      <td>-0.027474</td>\n",
       "      <td>1.159300</td>\n",
       "      <td>0.015676</td>\n",
       "      <td>0.191942</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.696352</td>\n",
       "      <td>0.024985</td>\n",
       "      <td>-1.059872</td>\n",
       "      <td>-0.403767</td>\n",
       "      <td>-0.678653</td>\n",
       "      <td>-2.939352</td>\n",
       "      <td>-2.736450</td>\n",
       "      <td>-1.965399</td>\n",
       "      <td>-0.805868</td>\n",
       "      <td>-1.139434</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>0.965614</td>\n",
       "      <td>-2.380547</td>\n",
       "      <td>0.625297</td>\n",
       "      <td>-1.741256</td>\n",
       "      <td>-0.845366</td>\n",
       "      <td>0.949687</td>\n",
       "      <td>1.093801</td>\n",
       "      <td>0.819736</td>\n",
       "      <td>-0.284620</td>\n",
       "      <td>...</td>\n",
       "      <td>0.259746</td>\n",
       "      <td>0.357115</td>\n",
       "      <td>-1.893128</td>\n",
       "      <td>0.255107</td>\n",
       "      <td>0.163309</td>\n",
       "      <td>-1.021929</td>\n",
       "      <td>-2.077843</td>\n",
       "      <td>-1.127629</td>\n",
       "      <td>0.331531</td>\n",
       "      <td>-2.179483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>0.075664</td>\n",
       "      <td>-1.728785</td>\n",
       "      <td>0.852626</td>\n",
       "      <td>0.272695</td>\n",
       "      <td>-1.841370</td>\n",
       "      <td>0.327936</td>\n",
       "      <td>1.251219</td>\n",
       "      <td>0.771450</td>\n",
       "      <td>0.030917</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.200404</td>\n",
       "      <td>0.061753</td>\n",
       "      <td>-2.273998</td>\n",
       "      <td>-0.039365</td>\n",
       "      <td>0.368801</td>\n",
       "      <td>-2.566551</td>\n",
       "      <td>-1.675044</td>\n",
       "      <td>-1.082050</td>\n",
       "      <td>-0.965218</td>\n",
       "      <td>-1.836966</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 2309 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Type         0         1         2         3         4         5         6  \\\n",
       "0     2  0.773344 -2.438405 -0.482562 -2.721135 -1.217058  0.827809  1.342604   \n",
       "1     2 -0.078178 -2.415754  0.412772 -2.825146 -0.626236  0.054488  1.429498   \n",
       "2     2 -0.084469 -1.649739 -0.241307 -2.875286 -0.889405 -0.027474  1.159300   \n",
       "3     2  0.965614 -2.380547  0.625297 -1.741256 -0.845366  0.949687  1.093801   \n",
       "4     2  0.075664 -1.728785  0.852626  0.272695 -1.841370  0.327936  1.251219   \n",
       "\n",
       "          7         8    ...         2298      2299      2300      2301  \\\n",
       "0  0.057042  0.133569    ...    -0.238511 -0.027474 -1.660205  0.588231   \n",
       "1 -0.120249  0.456792    ...    -0.657394 -0.246284 -0.836325 -0.571284   \n",
       "2  0.015676  0.191942    ...    -0.696352  0.024985 -1.059872 -0.403767   \n",
       "3  0.819736 -0.284620    ...     0.259746  0.357115 -1.893128  0.255107   \n",
       "4  0.771450  0.030917    ...    -0.200404  0.061753 -2.273998 -0.039365   \n",
       "\n",
       "       2302      2303      2304      2305      2306      2307  \n",
       "0 -0.463624 -3.952845 -5.496768 -1.414282 -0.647600 -1.763172  \n",
       "1  0.034788 -2.478130 -3.661264 -1.093923 -1.209320 -0.824395  \n",
       "2 -0.678653 -2.939352 -2.736450 -1.965399 -0.805868 -1.139434  \n",
       "3  0.163309 -1.021929 -2.077843 -1.127629  0.331531 -2.179483  \n",
       "4  0.368801 -2.566551 -1.675044 -1.082050 -0.965218 -1.836966  \n",
       "\n",
       "[5 rows x 2309 columns]"
      ]
     },
     "execution_count": 292,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_xtrain.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 297,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n"
     ]
    }
   ],
   "source": [
    "print('a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
